package com.finger.dao;

import com.finger.pojo.Source;
import com.finger.pojo.User;
import com.finger.pojo.UserLearnedWord;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Mapper
public interface UserDao {
    @Select("select * from user where id = #{id}")
    public User getUserById(Integer id);

    //根据用户名查询当前用户名是否已经存在
    @Select("select * from user where username = #{username}")
    public Boolean getUserByUsername(@Param("username") String username);

    //根据用户名和密码查询用户是否存在
    @Select("select * from user where username = #{username} and password = #{password}")
    public User getUserByUsernameAndPassword(@Param("username") String username,@Param("password") String password);

    //添加用户
    @Insert("insert into user (username,password,achievement) values(#{username},#{password},#{achievement})")
    public Boolean addUser(@RequestParam User user);

    //用户成就信息变更
    @Update("update user set achievement = #{achievement} where id = #{id}")
    public Boolean updateUserAchievement(@Param("id") Integer id,@Param("achievement") String achievement);

    @Select("select * from user;")
    public List<User> getAllUser();
    
    @Select("select * from user_learned_words where uid = #{uid};")
    public List<UserLearnedWord> getUserLearnedWordsByUid(Integer uid);

    // 用户创建词源
    @Insert("insert into source (source_id,name,scope) values (null,#{name},#{scope});")
    public Boolean createSource(Source source);

    // 用户切换词源
    @Update("update user set source = #{source} where id = #{id};")
    public Boolean updateUserSource(User user);

}
